#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "qstring.h"
#include "qlistwidget.h"
#include "qdebug.h"
#include "QSequentialAnimationGroup"
#include "QPropertyAnimation"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
   // , ui(new Ui::MainWindow)
{
    setFixedSize(500,500);
    auto  widget = new QWidget(this);
    widget->setFixedSize(500,500);
    //ui->setupUi(this);
    m_listwidget = new QListWidget(widget);
    m_listwidget->addItem("hhhh");
    m_listwidget->addItem("hhhh");
    m_listwidget->addItem("hhhh");
    m_listwidget->addItem("hhhh");
    m_listwidget->addItem("hhhh");
   // listWidget->hide();
   auto btn = new QPushButton(widget);
   btn->setFixedSize(40,40);
   btn->setText("open");
   //btn->move(0,0);
   auto btn_ = new QPushButton(widget);
   btn_->setText("close");
   btn_->setFixedSize(50,40);

   //m_listwidget->setFixedSize(200,200);
   m_listwidget->hide();

   auto lay = new QHBoxLayout(widget);
   //lay->setDirection(QBoxLayout::BottomToTop);
   lay->setSpacing(50);
   //lay->setContentsMargins(0,0,0,0);
   lay->setContentsMargins(20,20,20,20);
   lay->addWidget(btn,1);
   lay->addSpacing(20);
   //lay->addStretch(1);
   lay->addWidget(btn_,20);

    connect(btn,&QPushButton::clicked,this,[this,btn,btn_]()
    {
        m_listwidget->show();
        QPropertyAnimation *pScaleAnimation1 = new QPropertyAnimation(m_listwidget, "geometry");
        pScaleAnimation1->setDuration(300);
        auto x = btn->pos().x();
        auto y = btn->pos().y();
        pScaleAnimation1->setStartValue(QRect(100,100,200,0));
        pScaleAnimation1->setEndValue(QRect(100,100, 200, 200));
        pScaleAnimation1->start();


//        QPropertyAnimation *animation = new QPropertyAnimation(m_listwidget, "geometry");
//        animation->setDuration(10000);
//        animation->setStartValue(QRect(0, 0, 100, 30));
//        animation->setEndValue(QRect(250, 250, 100, 30));
//
//        animation->start();
       // m_listwidget->show();
    });
    connect(btn_,&QPushButton::clicked,this,[&]()
    {
        m_listwidget->hide();
    });




}

MainWindow::~MainWindow()
{
    //delete ui;
}

